<!DOCTYPE html>
<!-- saved from url=(0030)http://account.test.56zxr.com/ -->
<html lang="en" xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="./api/bootstrap.min.css" rel="stylesheet">
    <script src="./api/jquery-1.6.js"></script>
     <script src="./api/jQuery.md5.js"></script>
    <script src="./api/bootstrap.min.js"></script>
    <title>App接口测试</title>
</head>
<body>
    <div class="container panel panel-primary">
        <div class="panel-header text-center lead">App接口测试(先生成json再执行)XXXX</div>
		<div class="panel-header text-center lead">可选地址:http://localhost:8090/ownerapp,https://test-ownerapp.hayll.cn/ownerapp,http://ownerapp.hayll.cn/ownerapp</div>
        <!-- uploadImg.do -->
        <form class="form-horizontal" id="fm" action="managerApi/uploadImg.do" method="post" enctype="multipart/form-data">
            <div class="form-group">
                <label class="col-md-2">服务器地址:</label>
                <div class="col-md-10">
                    <input type="text" class=" form-control" id="apiurl" name="apiurl" value="https://test-ownerapp.hayll.cn">
                    <input type="text" class=" form-control" id="realurl" name="realurl" value="xxx">
                    <input type="text" class=" form-control" id="type" name="type" value="json">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2">请求方法</label><div class="col-md-10">
                    <select class="form-control" name="method">
                        <option>Get</option>
                        <option selected="selected">Post</option>
                        <option>Options</option>
                    </select>
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2">账户</label>
                <div class="col-md-3">
                    <input class="form-control" name="phone" id="phone" value="13911310340"/>
                </div>
                <div class="col-md-1">
                    	密码:
                </div>
                <div class="col-md-2">
                    	<input class="form-control" name="validateCode" id="validateCode" value="123456"/>
                </div>
                <div class="col-md-2">
                	<input type="button" id="sendValidate_input" class="form-control" value="发送验证码json" name="sendValidate_input" onclick="sendValidate()">
                </div>
                <div class="col-md-2">
                	<input type="button" id="login_input" class="form-control" value="登录json" name="lastPos_input" onclick="managerLogin()">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2">临时</label>
                <div class="col-md-5">
                    <input type="text" id="getRoomInfoList_input" class="form-control" value="" name="getRoomInfoList_input">
                </div>
                 <div class="col-md-5">
                	<input type="text" id="listVillagePassword_input" class="form-control" value="" name="listVillagePassword_input">
                </div>
            </div>
            <div class="form-group">
                <label class="col-md-2">上传文件</label>
                <div class="col-md-5">
					<input type="file" name="files" value="选择"/> 
					<!--input type="file" name="files" value="选择"/> -->
					<!-- input type="file" name="files" value="选择"/> -->
					<input type="submit" value="上传" />
					小区id<input type="text" name="villageId" value="1" />
					<input type="button" value="下载" onclick="downloadFileByForm()"/>
                </div>
			</div>
            <div class="form-group">
                <label class="col-md-2">请求参数（json）</label><div class="col-md-10">
                    <textarea class=" form-control text-info lead" rows="6" name="paras" id="paras">{"head":{"sequenceCode":"C8B4BCCC-254A-4039-87C8-9E6E8F0E642F","appVersion":"1.0.0","protocolVersion":"1.0","callType":"web","systemVersion":"10.3","requestTime":"1498544237000","mobileModel":"chrome58"},"body":{"validateCode":"123456","phone":"13911310340","loginType":1}}
                    </textarea>
                </div>
            </div>
            <div class="form-group">
                <input type="button" id="btnRun" class="form-control" value="执行" name="cmdexecute" onclick="RunTest()">
            </div>
            <div class="form-group">
                <label class="col-md-2">登录状态</label>
                <div class="col-md-20 red">
                    <strong id="isLogin">未登录</strong>
                </div>

            </div>
        </form>
        <div class="panel panel-info">
            <div class="panel-heading">
                <p class="panel-header">返回结果</p>
            </div>
            <div class="panel-body" style="height: 300px; overflow: scroll;">
                <table class="text-success table-bordered">
                    <thead>
                        <tr>
                            <th>耗时(ms)</th>
                            <th>返回结果</th>
                        </tr>
                    </thead>
                    <tbody id="result"><tr><td>162</td><td>xxx</td></tr></tbody>
                </table>
            </div>
        </div>

    </div>
    <script type="text/javascript">
       var userToken='xxxx';
       var userId='xxxxx';
       var apiAuthKey='hayll2017';
       var headObj={"sequenceCode":"C8B4BCCC-254A-4039-87C8-9E6E8F0E642F","appVersion":"3.0.0","protocolVersion":"1.0","callType":"IOS","systemVersion":"10.3","requestTime":"1498544237000","mobileModel":"iPhone"};
        headObj.token="130f1cdf3c7e4f22be9d90be8250d0d4";
		headObj.phone="13800000001";
		headObj.bizId="25";
        $(function () {
            $(document).bind('ajaxSend', function () { $("#btnRun").attr('disabledXXX', 'disabledXXX'); }).
                bind('ajaxComplete', function () { $("#btnRun").removeAttr('disabled'); }).bind('ajaxError', function () {
                    $("#btnRun").removeAttr('disabled');
                });
            $("#apiurl").val(GetUrlRelativePath());
            $("#realurl").val($("#apiurl").val()+"/managerApi/login.do");
            /*
            
            */
            function GetUrlRelativePath()
	          　　{
	          　　　　var url = document.location.toString();
	          　　　　var arrUrl = url.split("//");
	             var host_path=arrUrl[1]; 
	             var arrPath = host_path.split("/");
	          　　　　//var start = arrUrl[0]+arrUrl[1];
	          　　　　var relUrl = arrUrl[0]+"//"+arrPath[0]+"/"+arrPath[1];//s
	          　　　　if(relUrl.indexOf("?") != -1){
	          　　　　　　relUrl = relUrl.split("?")[0];
	          　　　　}
	          　　　　return relUrl;
	          　　}
        });
		/**执行测试 */
        function RunTest() {
            var obj = $("#fm").serializeArray();
            obj = ConverToJson(obj);
            
            $("#result").html("");
          
            RunApi(obj);
        }

        function ConverToJson(ary) {
            var json = {};
            $.each(ary, function (i, data) {
                if (json[data.name]) {
                    var v = json[data.name];
                    if (typeof (v) == "object")
                        v.push(data.value);
                    else {
                        var ary = [];
                        ary.push(v);
                        ary.push(data.value);
                    }
                    json[data.name] = ary;

                } else {
                    json[data.name] = data.value;
                }

            });
            return json;
        }

        function RunApi(obj) {
            var dt = new Date();
            var dataObj = jQuery.parseJSON(obj.paras);
            dataObj.head=headObj;
            dataObj.sign=apiAuthKey;
            var md5Str = $.md5(JSON.stringify(dataObj));//,"sign":apiAuthKey
            dataObj.sign=md5Str;
        	var dataStr=JSON.stringify(dataObj);
        	
            $.ajax({
                type: obj.method,
                url: obj.realurl,
                dataType: (obj.type)?obj.type:'json',
                cache: false,
                data: obj.method=="Get"?("p="+dataStr):dataStr,
                contentType: 'text/html; charset=utf-8',
                success: function (d) {
                    if (typeof (d) == "string" || typeof (d) == "number") {
                        AppendMsg({data:jQuery.parseJSON(d)});
                    }
                    else {
                        AppendMsg(d);
                    }

                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                	AppendMsg({data:jQuery.parseJSON(s),errorCode:textStatus});
                },
            });
        }
        /**
        {"body":{"avatar":"","id":102,"lastLoginTime":"2017-03-08 10:08","name":"测试","phone":"15255557777","token":"C609E5CC9CAFBBFE74FA1E18441FBFAC"},"code":"0000","isEncrypt":"0","message":"SUCCESS","userToken":"C609E5CC9CAFBBFE74FA1E18441FBFAC"}
        */
        function AppendMsg(msg) {
        	if(msg.body){
        		if(msg.body.token){
	        		userToken=msg.body.token||userToken;
	        		//var obj =jQuery.parseJSON(msg.data);
	        		userId=msg.body.userId||userId;
	        		headObj.token=userToken;
	        		headObj.phone=msg.body.phone;
	        		headObj.bizId=msg.body.userId||msg.body.ownerId;
	        		headObj.bizId=headObj.bizId+'';
	        		$("#isLogin").text("已登录,userToken:"+userToken+",userId:"+userId);
        		}
        	}
            var row = $("<tr></tr>");
            row.append($("<td></td>").html(msg.time)).append($("<td></td>").html(JSON.stringify(msg)));
            row.appendTo($("#result"));

        }
        function unicode2Char(str) {
       		return (str.replace(/\\/g, "%"));
       	}
        function ObjectToString(obj) {
            var res = "";
            for (var p in obj) {
                if (typeof (obj[p]) == "object") {
                    res = res + p + ":{" + ObjectToString(obj[p]) + "},";
                }
                else
                    res += p + ":" + obj[p] + ",";
            }
            return res;
        }
        /**
        json字符串转json对象：jQuery.parseJSON(jsonStr);
		json对象转json字符串：JSON.stringify(jsonObj);
		货主请求：{"header":{"userToken":"7bcab6df-2d67-4627-9db3-1b8c36edd982"},"method":"promptInformation","myParams":[8155],"service":"com.zxr.xline.service.TruckRequireService","uuid":"6d51b847-5fc8-122a-342f-b283c4e4f30e"}
        */
        function sendValidate(){
        	var param={"head":headObj,"body":{"type":1,"phone":$("#phone").val()}};
        	//{"head":{"sequenceCode":"C8B4BCCC-254A-4039-87C8-9E6E8F0E642F","appVersion":"3.0.0","protocolVersion":"1.0","callType":"IOS","systemVersion":"10.3","requestTime":"1498544237000","mobileModel":"iPhone"},"sign":"1689815e4615c7da7320ecfc9931b2fa","body":{"phone":"18912345678","password":"670b14728ad9902aecba32e22fa4f6bd"}}
        	//var md5Str = $.md5(JSON.stringify(param));//,"sign":apiAuthKey
        	//param.sign=md5Str;
        	$("#paras").val(JSON.stringify(param)+"");
        	$("#realurl").val($("#apiurl").val()+"/managerApi/sendValidateCode.do");
        }
        
        function managerLogin(){
        	headObj.phone=$("#phone").val();
        	var param={"head":headObj,"body":{"password":$.md5($("#validateCode").val()),"phone":$("#phone").val()}};
        	$("#paras").val(JSON.stringify(param)+"");
        	$("#realurl").val($("#apiurl").val()+"/managerApi/login.do");
        }
        function fastOpenDoor(){
        	var param={"head":headObj,"body":{"switchId":1,"roomId":1}};
        	$("#paras").val(JSON.stringify(param)+"");
        	$("#realurl").val($("#apiurl").val()+"/managerApi/fastOpenDoor.do");
        }
        function lookAtDoorSwitch(){
        	var param={"head":headObj,"body":{"switchId":1,"roomId":1}};
        	$("#paras").val(JSON.stringify(param)+"");
        	$("#realurl").val($("#apiurl").val()+"/managerApi/lookAtDoorSwitch.do");
        }
     	// 模拟表单提交同步方式下载文件
        // 能够弹出保存文件对话框
        function downloadFileByForm() {
        	$("#type").val("text");
        	var dataObj={"head":headObj,"body":{"switchId":1,"roomId":1}};
        	var url = $("#apiurl").val()+"/managerApi/testDownload.do";
            dataObj.head=headObj;
            dataObj.sign=apiAuthKey;
            var md5Str = $.md5(JSON.stringify(dataObj));//,"sign":apiAuthKey
            dataObj.sign=md5Str;
            
        	 var form = $("<form></form>").attr("action", url).attr("method", "post");
             form.append($("<input></input>").attr("type", "hidden").attr("name","p").attr("value", JSON.stringify(dataObj)));
             form.appendTo('body').submit().remove();
        }
    </script>




</body></html>